var dragBody = false;
var dragIndex = false;
var dragFs = false;


function setDownOnFs(event) {
	tmpMouseXPosition = event.clientX;
	tmpMouseYPosition = event.clientY;
	dragFs = true
}

function setDownOnBody(event) {
	tmpMouseXPosition = event.clientX;
	tmpMouseYPosition = event.clientY;
	dragBody = true;
	}


function setUpOnFs(event) {
	dragFs = false
}

function setUpOnBody(event) {
	dragBody = false
}

function setDownOnNav(event) {
	tmpMouseXPosition = event.clientX;
	tmpMouseYPosition = event.clientY;
	dragIndex = true
}

function setUpOnNav(event) {
	dragIndex = false
}

function startRedoTimer() {
	redoTimer = setInterval(redoPositions, 10);

}

function redoPositions() {

	if(draggedBubble) {
		draggedBubble.style.zIndex = 3;
		if((parseFloat($(draggedBubble).css("left").split("px")[0])) + (parseFloat($(draggedBubble).css("width").split("px")[0])) > 1200 && parseFloat(document.getElementById("Navigator_index").style.left.split("px")[0]) <= 1330) {
			document.getElementById("minibubbleNumber" + draggedBubble.id.split("container")[1]).style.left = parseFloat(document.getElementById("minibubbleNumber" + draggedBubble.id.split("container")[1]).style.left.split("px")[0]) + 3 / 15 + "px";
			originalMiniX += 3/15 ;
			document.getElementById("Navigator_index").style.left = parseFloat(document.getElementById("Navigator_index").style.left.split("px")[0]) + 3 / 15 + "px";

			for(i in arrayBubble) {
				
				if("container" + i != draggedBubble.id && document.getElementById("container" + arrayBubble[i].bubble.bubbleID())) {
					document.getElementById("container" + arrayBubble[i].bubble.bubbleID()).style.left = parseFloat(document.getElementById("container"+ arrayBubble[i].bubble.bubbleID()).style.left.split("px")[0]) - 3 + "px";

				}
			}
		} else if((parseFloat($(draggedBubble).css("left").split("px")[0])) < 100 && parseFloat(document.getElementById("Navigator_index").style.left.split("px")[0]) >= 10) {
			document.getElementById("minibubbleNumber" + draggedBubble.id.split("container")[1]).style.left = parseFloat(document.getElementById("minibubbleNumber" + draggedBubble.id.split("container")[1]).style.left.split("px")[0]) - 3 / 15 + "px";
			originalMiniX -= 3/15
			document.getElementById("Navigator_index").style.left = parseFloat(document.getElementById("Navigator_index").style.left.split("px")[0]) - 3 / 15 + "px";

			for(i in arrayBubble) {
				if("container" + i != draggedBubble.id && document.getElementById("container" + arrayBubble[i].bubble.bubbleID())) {
					document.getElementById("container" + arrayBubble[i].bubble.bubbleID()).style.left = parseFloat(document.getElementById("container"+ arrayBubble[i].bubble.bubbleID()).style.left.split("px")[0]) + 3 + "px";
				}
			}
		}
	}

}

// qui c'e' da rivedere le condizioni di movimento (ora poco sbatti pero')

function dragFsEvent(e) {
	diffX = tmpMouseXPosition - e.clientX;
	diffY = tmpMouseYPosition - e.clientY;
	tmpMouseXPosition = e.clientX;
	tmpMouseYPosition = e.clientY;
	if(draggedBubble == null && dragBody == true) {
		document.getElementById("fs").style.left = parseFloat(document.getElementById("fs").style.left.split("px")[0]) - diffX + "px";
		document.getElementById("fs").style.top = parseFloat(document.getElementById("fs").style.top.split("px")[0]) - diffY + "px";
	}
}

function dragBodyEvent(e) {
	diffX = tmpMouseXPosition - e.clientX;
	diffY = tmpMouseYPosition - e.clientY;
	tmpMouseXPosition = e.clientX;
	tmpMouseYPosition = e.clientY;

	if(draggedBubble == null && dragBody == true) {

		if(parseFloat(document.getElementById("Navigator_index").style.left.split("px")[0]) >= 10 && parseFloat(document.getElementById("Navigator_index").style.left.split("px")[0]) <= 1330) {

			document.getElementById("Navigator_index").style.left = parseFloat(document.getElementById("Navigator_index").style.left.split("px")[0]) + diffX / 15 + "px";

			for(i in arrayBubble) {
				if(document.getElementById("container" + i))
					document.getElementById("container" + i).style.left = parseFloat(document.getElementById("container"+ i).style.left.split("px")[0]) - diffX + "px";
			}
		} else if(diffX > 0 && parseFloat(document.getElementById("Navigator_index").style.left.split("px")[0]) < 10) {

			document.getElementById("Navigator_index").style.left = parseFloat(document.getElementById("Navigator_index").style.left.split("px")[0]) + diffX / 15 + "px";

			for(i in arrayBubble) {
				if(document.getElementById("container" + i))
					document.getElementById("container" + i).style.left = parseFloat(document.getElementById("container"+ i).style.left.split("px")[0]) - diffX + "px";
			}

		} else if(diffX < 0 && parseFloat(document.getElementById("Navigator_index").style.left.split("px")[0]) > 1330) {

			document.getElementById("Navigator_index").style.left = parseFloat(document.getElementById("Navigator_index").style.left.split("px")[0]) + diffX / 15 + "px";

			for(i in arrayBubble) {
				if(document.getElementById("container" + i))
					document.getElementById("container" + i).style.left = parseFloat(document.getElementById("container"+ i).style.left.split("px")[0]) - diffX + "px";
			}

		}
	}
}

function dragIndexEvent(e) {
	diffX = e.clientX - tmpMouseXPosition;
	diffY = e.clientY - tmpMouseYPosition;
	tmpMouseXPosition = e.clientX;
	tmpMouseYPosition = e.clientY;

	if(parseFloat(document.getElementById("Navigator_index").style.left.split("px")[0]) >= 10 && parseFloat(document.getElementById("Navigator_index").style.left.split("px")[0]) <= 1330) {

		if(draggedBubble == null && dragIndex == true) {

			document.getElementById("Navigator_index").style.left = parseFloat(document.getElementById("Navigator_index").style.left.split("px")[0]) + diffX + "px";

			for(i in arrayBubble) {
				if(document.getElementById("container" + i))
					document.getElementById("container" + i).style.left = parseFloat(document.getElementById("container"+ i).style.left.split("px")[0]) - diffX * 15 + "px";
			}

		}

	} else if(diffX > 0 && parseFloat(document.getElementById("Navigator_index").style.left.split("px")[0]) < 10) {

		if(draggedBubble == null && dragIndex == true) {

			document.getElementById("Navigator_index").style.left = parseFloat(document.getElementById("Navigator_index").style.left.split("px")[0]) + diffX + "px";

			for(i in arrayBubble) {
				if(document.getElementById("container" + i))
					document.getElementById("container" + i).style.left = parseFloat(document.getElementById("container"+ i).style.left.split("px")[0]) - diffX * 15 + "px";
			}

		}

	} else if(diffX < 0 && parseFloat(document.getElementById("Navigator_index").style.left.split("px")[0]) > 1330) {


		if(draggedBubble == null && dragIndex == true) {

			document.getElementById("Navigator_index").style.left = parseFloat(document.getElementById("Navigator_index").style.left.split("px")[0]) + diffX + "px";

			for(i in arrayBubble) {
				if(document.getElementById("container" + i))
					document.getElementById("container" + i).style.left = parseFloat(document.getElementById("container"+ i).style.left.split("px")[0]) - diffX * 15 + "px";
			}

		}
	}
}






function navClick() {
	var tmpDiffX = 0
	var MouseXPosition = event.clientX;
	oldNavPosX = parseInt(document.getElementById("Navigator_index").style.left.split("px")[0])
	document.getElementById("Navigator_index").style.left = MouseXPosition - 40 + "px";

	if(parseInt(document.getElementById("Navigator_index").style.left.split("px")[0]) < 10) {
		tmpDiffX = 10 - parseInt(document.getElementById("Navigator_index").style.left.split("px")[0])
		document.getElementById("Navigator_index").style.left = "10px"
		diffNavX = MouseXPosition - 40 - oldNavPosX + tmpDiffX
	} else if(parseInt(document.getElementById("Navigator_index").style.left.split("px")[0]) > 1330) {
		tmpDiffX = parseInt(document.getElementById("Navigator_index").style.left.split("px")[0]) - 1330
		document.getElementById("Navigator_index").style.left = "1330px"
		diffNavX = MouseXPosition - 40 - oldNavPosX - tmpDiffX

	} else
		diffNavX = MouseXPosition - 40 - oldNavPosX + tmpDiffX
	for(i in arrayBubble) {
		if(document.getElementById("container" + i))
			document.getElementById("container" + i).style.left = parseInt(document.getElementById("container" + i).style.left.split("px")[0]) - diffNavX * 15 + "px";
	};
}